package com.obas.integration.element.telnet.editor;

import com.obas.integration.element.telnet.type.HWMacAddressType;
import com.obas.integration.element.telnet.type.HWPortFeatureType;
import com.obas.model.business.DeviceMacAddress;

public class HWDefaultTelnetEditor extends AbstractTelnetEditor {

	// TYPE MAC MAC TYPE F/S VLAN ID
	// eth 781d-ba30-f699 dynamic 0/17A 3002
	public DeviceMacAddress editAsText(String text) {

		String type = formatString(text.substring(2, 12));
		String mac = formatString(text.substring(12, 32));
		String macType = formatString(text.substring(32, 43));
		String fs = formatString(text.substring(43, 51));
		String vlanId = formatString(text.substring(51, 58));

		DeviceMacAddress deviceMacAddress = new DeviceMacAddress();

		HWPortFeatureType hWPortFeatureType = HWPortFeatureType.getByText(type);
		deviceMacAddress.setPortFeatureType(null != hWPortFeatureType ? hWPortFeatureType.getPortFeatureType() : null);

		deviceMacAddress.setMacAddress(asMacAddress(mac));

		HWMacAddressType hWMacAddressType = HWMacAddressType.getByText(macType);
		deviceMacAddress.setMacAddressType(null != hWMacAddressType ? hWMacAddressType.getMacAddressType() : null);

		deviceMacAddress.setPortCode(fs);
		deviceMacAddress.setVlan(vlanId);

		return deviceMacAddress;
	}

}
